package ui.classification;

import java.io.ByteArrayInputStream;

import org.dom4j.Document;
import org.dom4j.DocumentException;
import org.dom4j.io.SAXReader;

import preprocess.XmlTransfer;
import utils.ResourceCritical;

public class ResourceGetter extends Thread
{
    private SAXReader                  reader   = new SAXReader();
    private ResourceCritical<Resource> resource = null;

    public ResourceGetter(ResourceCritical<Resource> resource)
    {
        this.resource = resource;
    }

    @Override
    public void run()
    {
        int index = 0;
        byte[] xmlArray = null;
        String xmlName = null;
        Document doc = null;
        while (true)
        {
            if (!XmlTransfer.xmlNameList.isEmpty()
                    && !XmlTransfer.xmlList.isEmpty())
            {
                String tmp = XmlTransfer.xmlNameList.get(0);
                if (tmp.substring(0, tmp.length() - 4).equals(xmlName))
                {
                    try
                    {
                        Thread.sleep(10);
                    }
                    catch (Exception e)
                    {}
                    continue;
                }
                xmlArray = XmlTransfer.xmlList.get(0);
                xmlName = XmlTransfer.xmlNameList.get(0);
                xmlName = xmlName.substring(0, xmlName.length() - 4);

                Resource r = new Resource(xmlArray,xmlName);
                resource.push(r);
            }
        }
    }
}
